import request from '@/utils/request'

enum API {
  // 获取全部旅游的信息
  ALLTRAVEL_URL = '/admin/travel/info/',
  // 添加一条旅游信息
  ADDTRAVEL_URL = '/admin/travel/save',
  // 更新旅游信息
  UPDATETRAVEL_URL = '/admin/travel/update',
  // 删除某一个旅游信息
  DELETETRAVEL_URL = '/admin/travel/remove/',
  // 删除旅游模块的媒体数据
  DELETEMEDIA_URL = '/admin/travel/removeMedia/',
  // 获取图片测试
  GETMEDIA_URL = '/admin/travel/getMedia/',
  // 审核通过/下架
  UPDATEISONLINE_URL = '/admin/travel/updateisonline/',
}

// 获取全部旅游的信息
export const reqAllTravel = (
  page: number,
  limit: number,
  keyword: string,
  local: string,
) => {
  return request.get<any, any>(
    API.ALLTRAVEL_URL + `${page}/${limit}/?keyword=${keyword}&local=${local}`,
  )
}
// 添加或更新旅游信息
export const reqAddOrUpdateTravel = (data: any) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATETRAVEL_URL, data)
  } else {
    return request.post<any, any>(API.ADDTRAVEL_URL, data)
  }
}
// 删除某一个旅游信息
export const reqDeleteTravel = (id: number) => {
  return request.delete<any, any>(API.DELETETRAVEL_URL + id)
}
// 删除旅游模块的媒体数据
export const reqDeleteMedia = (filename: any) => {
  return request.delete<any, any>(API.DELETEMEDIA_URL + filename)
}
// 获取图片测试
export const reqGetMedia = (id: number) => {
  return request.get<any, any>(API.GETMEDIA_URL + id)
}
// 审核通过/下架
export const reqUpdateIsOnline = (id: number, is_online: number) => {
  return request.post(API.UPDATEISONLINE_URL + `/${id}/${is_online}`)
}
